{include file="public/header"/}
</head>
<body>
<style type="text/css" media="screen">
.layui-this{color:#000!important;background:#fff!important;} 
.layui-this::after {border-bottom:0!important;}
</style>
<div class="layui-fluid" id="LAY-component-layer-list">
    <div class="layui-col-md12 pd83">
        <div class="layui-col-sm12">
            <div class="layui-card hideshadow">
              <div class="layui-tab layui-tab-brief">
                <ul class="layui-tab-title" style="background-color:#f2f2f2;">
                    <a href="{:url('/tools/index')}"><li>数据备份</li></a>
                    <a href="{:url('/tools/restore')}"><li class="layui-this">数据还原</li></a>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-form toolbar">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <button data-type="batch_del" data-url="{:url('/tools/del')}" class="layui-btn icon-btn layui-btn-danger">批量删除</button>
                            </div>
                        </div>
                    </div>
                    <table class="layui-table" id="tableUser" lay-filter="tableUser"></table>
                </div>
               </div>
            </div>
            <div class="pcfclear"></div>
        </div>
    </div>
</div>
<script type="text/html" id="tableBarUser">
<a class="layui-btn layui-btn-primary layui-btn-sm" data-url="{:url('/tools/new_import')}" data-id="{{d.time}}" data-type="new_import">恢复</a>
<a class="layui-btn layui-btn-danger layui-btn-sm" data-url="{:url('/tools/downFile')}" data-id="{{d.time}}" data-type="xaizai">下载</a>
<a class="layui-btn layui-btn-sm" data-url="{:url('/tools/del')}" data-id="{{d.time}}" data-type="del">删除</a>
</script>
{include file="public/footer"/}
<script>
    layui.use(['layer','form','table'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;

        // 渲染表格
        var insTb = table.render({
            elem: '#tableUser',
            url: "{:url('/tools/restore')}",
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type:'checkbox'},
                {field: 'basename', title: '文件名称',},
                {field: 'version', title: '系统版本'},
                {field: 'part', title: '卷号'},
                {field: 'size', title: '数据大小',align: 'center'},
                {field: 'showtime', title: '备份时间',align: 'center'},
                {align: 'center', toolbar: '#tableBarUser', title: '操作', minWidth: 250}
            ]]
        });
        
        $(document).on("click","#LAY-component-layer-list .layui-btn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });

        var active = {
            // 恢复
            new_import: function(){
                var obj = this;
                var importtime = $(obj).attr('data-id');
                var url = $(obj).attr('data-url');
                layer.msg('确认还原数据吗？', {
                    btnAlign: 'c',
                    time: 0,
                    btn: ['确定', '取消'],
                    yes: function(index, layero){
                        layer.close(index);
                        layer.msg('还原中请勿刷新页面', {icon: 16,shade: 0.01});
                        $.ajax({
                            type: "POST",
                            url: url+"?time="+importtime,
                            dataType: 'json',
                            success: function (res) {
                                layer.closeAll();
                                if(res.status){
                                    layer.msg(res.msg, {icon: 1, time:1000});
                                }else{
                                    layer.msg(res.msg, {icon: 2,time:1000});
                                }
                            },
                            error:function(){
                                layer.closeAll();
                                layer.msg("未知错误，操作中断！", {icon: 2,time:1000});
                            }
                        });
                    }
                });
            },            
            // 下载
            xaizai: function(){
                var obj = this;
                var url = $(obj).attr('data-url');
                var xaizaitime = $(obj).attr('data-id');
                window.location.href = url+"?time="+xaizaitime;
            },
            // 删除
            del: function(){
                delfun(this);
                return false;
            },
            // 批量删除
            batch_del: function(){
                var checkRows = table.checkStatus('tableUser');
                if (checkRows.data.length === 0) {
                    layer.msg('请选择要删除的数据表', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.time;
                });
                batch_del(this, ids);
            }
        }
    });
</script>
</body>
</html>